package com.zbkj.common.constants;

import com.zbkj.common.model.project.CityWeight;
import com.zbkj.common.model.project.ProjectParamGuo;
import com.zbkj.common.model.project.ProjectParamJun;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Auther:
 * @Date: 2024/9/25 20:25
 * @Description:
 */
public class CityWeightConfConstants {

    public static Object REFRESH_LOCK = new Object();

    /**
     * 城市权重参数配置MAP  {key:城市code, value:权重配置对象}
     */
    public static ConcurrentHashMap<String, CityWeight> CITY_WEIGHT_MAP = null;

    /**
     * 军标项目 人月费用(元)
     */
    public static final BigDecimal JUN_PER_MONTH_FEE = BigDecimal.valueOf(22700);

    /**
     * 国标软件规模
     * @param funPoints
     * @param paramGuo
     * 初始功能点数*规模计数时机*(6.96/8)*应用类型*((分布式处理+性能+可靠性+多重站点)*0.025+1)*完整性级别*开发语言*开发团队背景
     */
    public static BigDecimal softwareFun1Calc(BigDecimal funPoints, ProjectParamGuo paramGuo) {
        if(Objects.isNull(funPoints) || Objects.isNull(paramGuo)) {
            return null;
        }
        return funPoints.multiply(paramGuo.getParamVal1()).multiply(paramGuo.getParamVal2())
                .multiply(paramGuo.getParamVal7()).multiply(paramGuo.getParamVal8()).multiply(paramGuo.getParamVal9())
                .multiply(
                        ((paramGuo.getParamVal3().add(paramGuo.getParamVal4()).add(paramGuo.getParamVal5()).add(paramGuo.getParamVal6())).multiply(new BigDecimal("0.025")).add(new BigDecimal("1")))
                )
                .multiply(new BigDecimal(6.96)).divide(new BigDecimal(8),2,RoundingMode.HALF_UP);
    }

    /**
     * 国标  软件评估费用计算
     * @param softwareFun
     * @param cityWeightVal
     * 费用：估算软件规模*人月基准单价
     * @return
     */
    public static BigDecimal softwareFee1Calc(BigDecimal softwareFun, BigDecimal cityWeightVal) {
        if(Objects.isNull(softwareFun) || Objects.isNull(cityWeightVal)) {
            return null;
        }
        return softwareFun.multiply(cityWeightVal).divide(new BigDecimal("21.75"),2, RoundingMode.HALF_UP);

    }

    /**
     * 军标 软件评估费用计算
     * @param softwareFun
     * 1项、估算软件规模
     * 2项、=IF(D11<=1000,8.46*D11,IF(D11<=2000,8460+(D11-1000)*6.08,IF(D11<=5000,8460+6080+(D11-2000)*5.27,
     *      IF(D11<=10000,8460+6080+15810+(D11-5000)*5.14,8460+6080+15810+25700+(D11-10000)*5.09))))
     * 3项、2项 / 176
     * 费用  = 2.27万 * 3项 * 1.05 * 1.06
     *
     * @return
     */
    public static BigDecimal softwareFee2Calc(BigDecimal softwareFun) {
        if(Objects.isNull(softwareFun)) {
            return null;
        }
        BigDecimal cas1 = BigDecimal.valueOf(1000),
                cas2 = BigDecimal.valueOf(2000),
                cas3 = BigDecimal.valueOf(5000),
                cas4 = BigDecimal.valueOf(10000);
        BigDecimal calcModel2 = BigDecimal.ZERO;
        if(cas1.compareTo(softwareFun) >= 0) {
            calcModel2 = softwareFun.multiply(new BigDecimal("8.46"));
        } else if(cas2.compareTo(softwareFun) >= 0) {
            calcModel2 = BigDecimal.valueOf(8460).add((softwareFun.subtract(cas1)).multiply(new BigDecimal("6.08")));
        } else if(cas3.compareTo(softwareFun) >= 0) {
            int tmpCount = 8460 + 6080;
            calcModel2 = BigDecimal.valueOf(tmpCount).add(
                            (softwareFun.subtract(cas2)).multiply(new BigDecimal("5.27")));
        } else if(cas4.compareTo(softwareFun) >= 0) {
            int tmpCount = 8460 + 6080 + 15810;
            calcModel2 = BigDecimal.valueOf(tmpCount).add((softwareFun.subtract(cas3)).multiply(new BigDecimal("5.14")));
        } else {
            int tmpCount = 8460 + 6080 + 15810 +25700;
            calcModel2 = BigDecimal.valueOf(tmpCount).add((softwareFun.subtract(cas4)).multiply(new BigDecimal("5.09")));
        }
       return  (calcModel2.multiply(CityWeightConfConstants.JUN_PER_MONTH_FEE).multiply(new BigDecimal("1.05")).multiply(new BigDecimal("1.06"))).divide(BigDecimal.valueOf(176),2,RoundingMode.HALF_UP);
    }

    /**
     * 军标：估算规模计算
     * @param funPoints
     * @param paramJun
     * 公式：功能点数*(1+0.1*(f1...+f7))
     * @return
     */
    public static BigDecimal softwareFun2Calc(BigDecimal funPoints, ProjectParamJun paramJun) {
        if(Objects.isNull(funPoints) || Objects.isNull(paramJun)) {
            return null;
        }
        int fsum = paramJun.getParamVal1() +  paramJun.getParamVal2() + paramJun.getParamVal3() + paramJun.getParamVal4()
                 + paramJun.getParamVal5() + paramJun.getParamVal6() + paramJun.getParamVal7();
        return funPoints.multiply(
                    (new BigDecimal(fsum).multiply(new BigDecimal(0.1)).add(new BigDecimal(1)))
               ).setScale(2,RoundingMode.HALF_UP);
    }
}
